package tech.aistar.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tech.aistar.mapper.ProductMapper;
import tech.aistar.pojo.Product;

import java.util.List;
@Service
public class ProductServiceImpl implements ProductService{
    @Autowired
    private ProductMapper productMapper;

    @Override
    public List<Product> listAll() {
        return productMapper.findAll();
    }

    @Override
    public PageInfo<Product> page(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Product> list = productMapper.findAll();
        PageInfo<Product> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
    
    // 通过likeKey模糊查询name
    @Override
    public PageInfo<Product> productNameLike(String likeKey,Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Product> list = productMapper.productNameLike(likeKey);
        PageInfo<Product> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
